package com.jims.master.common.db;

import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

/**
 * Created by 陈晓阳 on 2017/6/27.
 */
public class DynamicDataSource extends AbstractRoutingDataSource {
    private static final ThreadLocal<String> contextHolder = new ThreadLocal<String>();

    /**
     *
     * @author 陈晓阳
     * @date 2017/6/27.
     * @return the currentLookupKey
     */
    public static String getCurrentLookupKey() {
        return (String) contextHolder.get();
    }

    /**
     *
     * @author 陈晓阳
     * @date 2017/6/27.
     * @param currentLookupKey
     *            the currentLookupKey to set
     */
    public static void setCurrentLookupKey(String currentLookupKey) {
        contextHolder.set(currentLookupKey);
    }

    /*
     * (non-Javadoc)
     *
     * @see
     * org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource#
     * determineCurrentLookupKey()
     */
    @Override
    protected Object determineCurrentLookupKey() {
        return getCurrentLookupKey();
    }
}
